package com.black.web.app.my.myorders;

import com.black.app.domain.req.my.myorders.AppOrderAftersaleAddReq;
import com.black.app.domain.resp.my.myorders.AppOrderAfterSaleResp;
import com.black.app.domain.resp.my.myorders.AppOrderAftersaleDetailsResp;
import com.black.app.service.my.AppMyOrderAftersaleService;
import com.black.common.core.controller.BaseController;
import com.black.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "App-我的售后相关Api")
@RestController
@RequestMapping("/app/my/aftersale")
public class AppAfterSaleController extends BaseController {

    @Autowired
    private AppMyOrderAftersaleService myOrderAftersaleService;

    /**
     * 获取用户售后订单列表
     * @param userId
     * @return
     */
    @ApiOperation(value = "获取用户售后订单列表")
    @GetMapping(value = "/aftersale/{user_id}")
    public R<PageInfo<AppOrderAfterSaleResp>> list(@PathVariable(value = "user_id") Integer userId){
        PageInfo<AppOrderAfterSaleResp> page = this.myOrderAftersaleService.aftersaleList(userId);
        return R.ok(page);
    }

    /**
     * 获取用户售后订单详情
     * @param id
     * @return
     */
    @ApiOperation(value = "获取用户售后订单详情")
    @GetMapping(value = "/aftersale/details/{id}")
    public R<AppOrderAftersaleDetailsResp> findById(@PathVariable(value = "id") Integer id){
        AppOrderAftersaleDetailsResp resp = this.myOrderAftersaleService.finById(id);
        return R.ok(resp);
    }

    /**
     * 用户申请售后(新增订单售后)
     * @param req
     * @return
     */
    @ApiOperation(value = "用户申请售后(新增订单售后)")
    @PostMapping
    public R add(AppOrderAftersaleAddReq req){
       boolean res = this.myOrderAftersaleService.addOrderAftersale(req);
        return isSuccess(res);
    }



}
